home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Information / Digests / CSMP Digest / volume 1 / csmp-v1-150.txt < prev    next >
Encoding:
Text File  |  1994-12-08  |  43.5 KB  |  1,064 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Sun, 02 Aug 92       Volume 1 : Issue 150
  2.  
  3. Today's Topics:
  4.  
  5.     Emulating TrueType
  6.     Sending Apple events to the Finder.
  7.     Light-weight processes in a Mac program
  8.     need help writing a screensaver
  9.     Offscreen PixMaps
  10.     Apple Event problem
  11.     Getting the text from a TERec
  12.  
  13.  
  14.  
  15. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  16.  
  17. The digest is a collection of article threads from the internet newsgroup
  18. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-ure on my part, but PostScript determines what regions to
  19. >fill by crossing windings, and since TrueType is just an enhancement to
  20. >PS I'd assume it works the same way. To determine windings, draw an
  21. >imaginary line across your object at any point, and increment the wind
  22. >count when you cross a line drawn clockwise, and decrement your count
  23. >when the line is draw counterclockwise. A positive wind count  means
  24. >you are in a fill region. That is, if the outer circle is drawn
  25. >clockwise and the inner circle is drawn counterclockwise, than a
  26. >horizontal line across the 'o' would start with zero windings, cross
  27. >the first line and have one windings (so now we're filling) cross the
  28. >second line (so now we're through filling) cross the second line again
  29. >(so we're filling once more) and finally cross the first line a second
  30. >time (and we're back to our original fill status). [0 1 0 1 0] Note
  31. >that it is the change in the direction of the line crossed that is
  32. >important. That is, if the inner circle was drawn clockwise as well,
  33. >the total "winding" value would still be positive when you crossed the
  34. >second line [0 1 2 1 0] and you'd end up with a filled circle instead
  35. >of an 'o'. Or if the outer circle was wound in the opposite direction,
  36. >you would go [0 -1 -2 -1 0] and you would end up with two concentric
  37. >circles instead of an 'o' (since you are never positive and hence never
  38. >fill.)  Pick up an introductory postscript book (the adobe 'cookbooks'
  39. >are excellent) for better explanations. (or browse through the stuff
  40. >thats available for ftp on adboe.com)
  41.  
  42. Actually I'm trying to use a library that uses NURBS to describe
  43. surfaces and lets you pass it further NURBS curves to defines holes
  44. punched in the surfaces. Anybody got a good intro reference to NURBS?
  45.  
  46. I sort of know what I'm doing on this score. I wrote an article some
  47. years ago for MacTutor on how to draw the famous "teapot" on the mac
  48. using Graf3d.  It is composed of the 3-D analog of the quadratic planar
  49. bezier splines that make up true type characters. You haven't read it
  50. because MacTutor lost it before accepting it and I never got around to
  51. resubmitting it. Since I got tired of people distributing my trivial
  52. demo programs without the accompanying source code that was the
  53. _raison_d'etre_, I added a "Decompile" command to the menu which faked
  54. the THINK C "compiling' dialog running backwards, and created a mess of
  55. source files in the current directory, and also a THINK C version of
  56. the Graf3D library.
  57.  
  58. The current issue of the "born-again" MacTutor has some useful demo
  59. programs for 3-D animation, and an advertorial for a 3-D shaded surface
  60. package for $250.00 (source included.)
  61.  
  62. If anyone wants a copy of the 3-D teapot source code and article, mail
  63. $15.00 to 
  64. Mosaic Codes 
  65. Suite 2036 
  66. 2140 Shattuck Ave 
  67. Berkeley, CA 94704
  68. with a note saying "I want Teapot" and I'll send yoy a Mac floppy of
  69. the whole thing.
  70.  
  71. +++++++++++++++++++++++++++
  72.  
  73. From: parent@apple.com (Sean Parent)
  74. Date: 25 Jun 92 16:59:05 GMT
  75. Organization: Apple Computer, Inc.
  76.  
  77. In article <1992Jun13.035121.9411@well.sf.ca.us> oster@well.sf.ca.us 
  78. (David Phillip Oster) writes:
  79. > If you are interested, here is Jonathon's description of the
  80. > rasterization process:
  81. > >Pure conjecture on my part, but PostScript determines what regions to
  82. > >fill by crossing windings, and since TrueType is just an enhancement to
  83. > >PS I'd assume it works the same way.
  84.  
  85. TrueType is not "just an enhancement to PS." It is a VERY different 
  86. mechanism for rendering fonts. By convension TrueType fonts are drawn so 
  87. that they can be filled using a winding number algorithm as described but 
  88. the TrueType engine uses an xor algorithm when it fills. This is a simpler 
  89. algorithm where the state of the fill toggles as you cross an edge.
  90.  
  91. - ----------------------------------------------------------------------
  92. Sean Parent
  93. "Quality unattainable in a reasonable amount of time."
  94.  
  95. ---------------------------
  96.  
  97. From: molla@paone.uucp (Levent Mollamustafaoglu)
  98. Subject: Sending Apple events to the Finder.
  99. Date: 12 Jun 92 06:41:41 GMT
  100. Organization: Aiken Computation Lab, Harvard University
  101.  
  102. How can I send Apple events to the Finder itself, such as "Open
  103. Selection"? Inside Mac VI is not very clear about this. Normally
  104. for other applications I can determine the target address by using
  105. AECreateDesc and the application signature, then I can use the
  106. descriptor record in AECreateAppleEvent. But I'm confused about
  107. what to do when the target is the Finder.
  108.  
  109. Any help from AE gurus is very much appreciated.
  110.  
  111.  
  112. ===========================================================================
  113. Dr. Levent Mollamustafaoglu       Harvard University    
  114. molla@paone.harvard.edu    molla@metatron.harvard.edu
  115. ===========================================================================
  116.  
  117. +++++++++++++++++++++++++++
  118.  
  119. From: jackl@austin.apple.com (Jack Littleton)
  120. Date: 12 Jun 92 17:34:09 GMT
  121. Organization: Apple Computer, Inc.
  122.  
  123. In article <1992Jun12.064141.2357@das.harvard.edu>, molla@paone.uucp (Levent Mollamustafaoglu) writes:
  124. > How can I send Apple events to the Finder itself, such as "Open
  125. > Selection"? Inside Mac VI is not very clear about this. Normally
  126. > for other applications I can determine the target address by using
  127. > AECreateDesc and the application signature, then I can use the
  128. > descriptor record in AECreateAppleEvent. But I'm confused about
  129. > what to do when the target is the Finder.
  130.  
  131. There are several things you can do.  You can still use the finder's
  132. signature, or you can use the process manager's GetNextProcess routine to 
  133. loop through all processes until you find the Finder's process number, and 
  134. use that for the address descriptor.
  135.  
  136. How to loop through the open processes is shown in Inside Mac VI, page 29-11.
  137. Once you have the ProcessSerialNumber for the Finder, you don't need to do
  138. the loop anymore.  That is, unless the Finder quits and relaunches (for
  139. whatever reason), and thus gets a new ProcessSerialNumber.  If the Finder
  140. does get a new serial number, AESend will return -903, and that's your que
  141. to look for a new ProcessSerialNumber (do the loop thing again).
  142.  
  143. - --
  144. Jack Littleton
  145. Developer Tools Engineering Group
  146. Apple Computer, Inc.
  147.  
  148. +++++++++++++++++++++++++++
  149.  
  150. From: prw@Apple.COM (Paul Wenker)
  151. Date: 26 Jun 92 17:50:16 GMT
  152. Organization: Apple Computer Inc., Cupertino, CA
  153.  
  154. In article <27238@goofy.Apple.COM> jpugh@apple.com (Jon Pugh) writes:
  155. >In article <1992Jun12.064141.2357@das.harvard.edu>, molla@paone.uucp (Levent Mollamustafaoglu) writes:
  156. >> 
  157. >> How can I send Apple events to the Finder itself, such as "Open
  158. >> Selection"? Inside Mac VI is not very clear about this. Normally
  159. >> for other applications I can determine the target address by using
  160. >> AECreateDesc and the application signature, then I can use the
  161. >> descriptor record in AECreateAppleEvent. But I'm confused about
  162. >> what to do when the target is the Finder.
  163. >
  164. >ThatUs the way to do it.
  165. >
  166. >    kFinderSignature            = 'MACS';
  167. >
  168. >    aSig := kFinderSignature;
  169. >    err := AECreateDesc(typeApplSignature, @aSig, 4, finderAddress);
  170. >
  171. >Jon
  172. >kAERegistrar
  173.  
  174.  
  175. Here are some things to keep in mind when sending events to the Finder.
  176.  
  177. 1) Be sure you can handle the case where the Finder isn't running.  There
  178. are cases now (and there will be more in the future) where the Finder gets 
  179. replaced by another shell program.
  180.  
  181. 2) If you want to send an event to the current shell program, as opposed
  182. to the Finder specifically, you can loop through the existing
  183. processes looking for a process of type 'FNDR' and then use the
  184. ProcessSerialNumber of that process as your destination address.
  185.  
  186. 3) If you send an event to the current shell program, be sure you handle
  187. cases where that program doesn't support some or all of the Finder's events.
  188.  
  189. 4) Also, be aware that the current shell program and the Finder may both
  190. be running (i.e. there are two processes of type 'FNDR' running).  It's
  191. unlikely that any replacement shell program could do everything that the
  192. Finder does, so there will probably be times when the user needs to run
  193. the Finder in addition to their shell program.
  194.  
  195.  
  196. - -Paul Wenker
  197. - -Apple Computer
  198.  
  199. +++++++++++++++++++++++++++
  200.  
  201. From: molla@paone.uucp (Levent Mollamustafaoglu)
  202. Date: 26 Jun 92 19:16:17 GMT
  203. Organization: Aiken Computation Lab, Harvard University
  204.  
  205. In article <69283@apple.Apple.COM> prw@Apple.COM (Paul Wenker) writes:
  206. >
  207. >Here are some things to keep in mind when sending events to the Finder.
  208. >
  209. >1) Be sure you can handle the case where the Finder isn't running.  There
  210. >are cases now (and there will be more in the future) where the Finder gets 
  211. >replaced by another shell program.
  212. >
  213.  
  214. Another case to consider is when there is no shell and no Finder running.
  215. (Just add the Quit command to the Finder, launch other applications, then
  216. quit from the Finder) It seems the best way is to send the event to the
  217. Finder and deal with errors when you can not get a result. Using the
  218. process manager is also a good idea, but I would prefer to rely on the
  219. events themselves, instead of the Process Manager, which might change.
  220.  
  221. Thanks for all the help.
  222.  
  223.  
  224. ===========================================================================
  225. Dr. Levent Mollamustafaoglu       Harvard University    
  226. molla@paone.harvard.edu    molla@metatron.harvard.edu
  227. ===========================================================================
  228.  
  229. ---------------------------
  230.  
  231. From: samuel@cyklop.nada.kth.se (Samuel Cederlund)
  232. Subject: Light-weight processes in a Mac program
  233. Date: 21 Jun 92 16:34:28 GMT
  234. Organization: Royal Institute of Technology, Stockholm, Sweden
  235.  
  236.  
  237.  
  238. I'm writing a package for light-weight processes on the mac. The code is pretty
  239. straightforward. Stacks are allocated off a global array, ie
  240.  
  241. unsigned char    stacks[0x4000];
  242.  
  243. I'm using MPW 3.2 and Macsbug in 7.0.
  244. Changing the stack pointer seems to break the system, however. I have managed to
  245. run the program as an MPW tool by changing to user mode in the debugger.
  246.  
  247. I understand changing the stack pointer into some heap-allocated block would
  248. cause an error like "stack has grown into heap" or something similar. But global
  249. variable space?
  250.   Now, if there be a compelling reason why the SP must be in the stack area, then
  251. a solution would be simply to *grow* the stack area. Can this be done?
  252.  
  253.  
  254. I'd gratefully appreciate any comments on the above from anybody with greater
  255. insights than myself (5 000 000 000, although I hope not all of them read this
  256. newsgroup :-)).
  257.  
  258.     Sam
  259.  
  260. Samuel Cederlund        | "When a true genius appears in the world,
  261. programming Mac         |  it is the sign that the dunces are all in
  262. samuel@nada.kth.se        |  confederacy against him."
  263.  
  264. +++++++++++++++++++++++++++
  265.  
  266. From: hammett@sbsu1.aukuni.ac.nz (Tim Hammett)
  267. Date: 21 Jun 92 21:46:47 GMT
  268. Organization: University of Auckland, New Zealand.
  269.  
  270. samuel@cyklop.nada.kth.se (Samuel Cederlund) writes:
  271. >I'm writing a package for light-weight processes on the mac. The code is pretty
  272. >straightforward. Stacks are allocated off a global array, ie
  273.  
  274. >unsigned char    stacks[0x4000];
  275.  
  276. >I'm using MPW 3.2 and Macsbug in 7.0.
  277. >Changing the stack pointer seems to break the system, however. I have managed t
  278. >run the program as an MPW tool by changing to user mode in the debugger.
  279.  
  280. There are two problems with implementing threading by changing your stack
  281. pointer. First, as you have mentioned, if you put your stacks in the
  282. heap, a "stack has collided with heap" system error will probably
  283. occur. Second, some Toolbox/OS/System (not sure which) routines treat
  284. the space between A7 & the top of the heap as scratch space. This eliminates
  285. the avenue of allocating your threads' stacks on the stack.
  286.  
  287. This leaves the option of implementing your threading routines by
  288. stack copying. A package which does this (although source is not
  289. available) can be found in Apple's develop magazine, issue 6 (with additional
  290. info in issue 7), and on the developer CD's. There is also some (non-Mac
  291. specific information on threading in the AT&T C++ documentation that comes
  292. with MPW C++.
  293.  
  294. - --
  295. Tim Hammett, Botany Dept, Auckland University, New Zealand.
  296. t.hammett@aukuni.ac.nz   Phone: +64-9-373-7599 x8365    FAX: +64-9-373-7416
  297.  
  298. ---------------------------
  299.  
  300. From: slchambe@athena.mit.edu (Stephen L Chamberlin)
  301. Subject: need help writing a screensaver
  302. Date: 21 Jun 92 20:37:51 GMT
  303. Organization: Massachusetts Institute of Technology
  304.  
  305. I'm just getting started trying to write a simple screensaver which runs as a 
  306. background application with System 7, and I'm having trouble figuring out how
  307. to black out the screen. There doesn't seem to be any obvious way of turning
  308. the whole screen black from a background app. The only solutions I've come up
  309. with so far are:
  310.  
  311. 1. Create a new GrafPort the size of the main screen and paint it black. This
  312. doesn't work very well because the finder still redraws the icons for mounted
  313. drives on top of my nice new GrafPort, and certain other things like flashing
  314. cursors seem to poke through as well.
  315.  
  316. 2. Create a new, borderless window the size of the screen and paint it black.
  317. This works great as long as my screensaver app is the current app, but if it's
  318. in the background, the black window appears BEHIND the windows of the current 
  319. app, which makes it pretty useless as a screensaver. Calls to SelectWindow() 
  320. and BringToFront() don't seem to work. Apparently something prevents an 
  321. application running in the background from making one of its windows the
  322. front window.
  323.  
  324. Any great ideas? I'm wondering how screensavers such as After Dark black out
  325. the screen. Any ideas or input on this topic would be appreciated. Thanks!
  326.  
  327. Steve Chamberlin - slchambe@athena.mit.edu
  328.  
  329. +++++++++++++++++++++++++++
  330.  
  331. From: bi341@cleveland.Freenet.Edu (Steve G. Crutchfield)
  332. Organization: Case Western Reserve University, Cleveland, Ohio, (USA)
  333. Date: Mon, 22 Jun 92 05:42:29 GMT
  334.  
  335.  
  336. The first method you mentioned is, I think, the best way to go
  337. about it.  You can prevent other applications from drawing over
  338. your port by setting the global variable grayRgn to an empty
  339. region (of course you have to save it so you can restore it
  340. later).  Then, use the obscure Window Manager routine
  341. CalcVisBehind, passing it a pointer to the frontmost window,
  342. and the OLD grayRgn.  This makes sure the window manager knows
  343. that no drawing can take place in any windows.
  344.  
  345. You can also prevent things like SuperClock from appearing by
  346. setting the global variable mBarHeight to 0.  (You have to
  347. reset this one too, of course!)
  348.  
  349. Hope this helps.
  350.  
  351. Steve Crutchfield
  352. stevec@imsa.edu
  353.  
  354.  
  355. ---------------------------
  356.  
  357. From: Josh.Adams@bbs.oit.unc.edu (Josh Adams)
  358. Subject: Offscreen PixMaps
  359. Date: 12 Jun 92 12:31:16 GMT
  360. Organization: Extended Bulletin Board Service
  361.  
  362. What is the easiest way to have offscreen PixMaps? (yes, I thought awhile
  363. ago  when I was asking about type-casting PixMaps that I was doing it,
  364. but I was wrong...)  Anyway, I've heard something about gWorlds, but have
  365. not seen anything about them. I don't think they're in IM V, but they are in
  366. VI, which I don't have. If someone could tell me how to do offscreen PixMaps
  367. easily, I'd be very grateful...
  368.  
  369. Thanks...
  370. Josh
  371.  
  372. - --
  373.    The opinions expressed are not necessarily those of the University of
  374.      North Carolina at Chapel Hill, the Campus Office for Information
  375.         Technology, or the Experimental Bulletin Board Service.
  376.            internet:  bbs.oit.unc.edu or 152.2.22.80
  377.  
  378. +++++++++++++++++++++++++++
  379.  
  380. From: zobkiw@world.std.com (Joe Zobkiw)
  381. Date: 12 Jun 92 12:45:11 GMT
  382. Organization: The World Public Access UNIX, Brookline, MA
  383.  
  384. To learn about offscreen pixmaps or bitmaps, read the technical note about
  385. them. I forget the number off the top of my head but 120 seems to stick
  386. in my mind. There are two notes, one on bitmaps, one of pixmaps. The code
  387. included in the notes is ALL YOU NEED to make it work.
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. - -- 
  395. - -- joe zobkiw                      Internet: zobkiw@world.std.com
  396. - --                                      AOL: AFL Zobkiw  
  397. - -- mac.synthesis.MIDI.THINK C.OOP.asm   CI$: 70712,515 
  398. - -- communications.networks.cool tunes...
  399.  
  400. +++++++++++++++++++++++++++
  401.  
  402. From: vvann@umbio.med.miami.edu (Vince Vann)
  403. Organization: University of Miami Medical School
  404. Date: Fri, 12 Jun 1992 18:22:02 GMT
  405.  
  406. Josh.Adams@bbs.oit.unc.edu (Josh Adams) writes:
  407. : What is the easiest way to have offscreen PixMaps? (yes, I thought awhile
  408. : ago  when I was asking about type-casting PixMaps that I was doing it,
  409. : but I was wrong...)  Anyway, I've heard something about gWorlds, but have
  410. : not seen anything about them. I don't think they're in IM V, but they are in
  411. : VI, which I don't have. If someone could tell me how to do offscreen PixMaps
  412. : easily, I'd be very grateful...
  413.  
  414. First, you should read the macintosh technical note #120 entitled
  415. "Principia Offscreen Graphics Environments".  This covers everything you
  416. need to know about PixMaps, CGrafPorts, and GDevices, plus some info on
  417. 32-Bit QuickDraw GWorlds.  
  418.  
  419. Second, if you are using THINK C 5.02 and TCL, I have written two TCL 
  420. classes that handle everything needed to setup an offscreen color graphics
  421. environment.  If you are interested in these classes (CPixelWorld and
  422. CPixelWorldPane), please contact me via E-mail and I will send you the
  423. source.  
  424.  
  425. Note: I am currently revising the PixelWorld classes. As soon as I complete
  426. the revisions, I will submit the source to the <ftp.brown.edu> archive.
  427. I'll post a message to C.S.M.P as soon as they are available.  
  428.  
  429. Good luck, 
  430. Vince
  431.  
  432. - --
  433. Vincent R. Vann
  434. University of Miami
  435. School of Medicine
  436. Miami, FL
  437.  
  438. E-mail:  vvann@umbio.med.miami.edu
  439.  
  440. +++++++++++++++++++++++++++
  441.  
  442. From: gluttony@reed.edu!gluttony.reed.edu!pcalahan (Patrick John Calahan)
  443. Date: 16 Jun 92 19:56:17 GMT
  444. Organization: Reed College, Portland, OR
  445.  
  446.  
  447. I want to do drawings in offscreen pixmaps.  I set everything up
  448. with NewPixMap(), and for the most part it works ok.
  449. BUT
  450.  
  451. If I copybits to the pixmap and then to the screen, all non-white pixels  
  452. are drawn on the screen in black.  However, If I copybits the image  
  453. directly to the screen, it looks fine.  This suggests to me that I am  
  454. setting one of the pixmap's fields incorrectly. (?)
  455.  
  456. Can anyone send me some code which shows how to do this correctly?
  457. Mail to pcalahan@reed.edu or post here...
  458.  
  459. Thanx in advance,
  460.     Pat
  461.  
  462. +++++++++++++++++++++++++++
  463.  
  464. From: Jeremiah.Blatz@dartmouth.edu (Jeremiah Blatz)
  465. Date: 24 Jun 92 05:23:45 GMT
  466. Organization: Dartmouth College, Hanover, NH
  467.  
  468. In article <m0lxjdU-0006ChC@gluttony.reed.edu>
  469. gluttony@reed.edu!gluttony.reed.edu!pcalahan (Patrick John Calahan)
  470. writes:
  471.  
  472. > If I copybits to the pixmap and then to the screen, all non-white pixels  
  473. > are drawn on the screen in black.  However, If I copybits the image  
  474. > directly to the screen, it looks fine.  This suggests to me that I am  
  475. > setting one of the pixmap's fields incorrectly. (?)
  476.  
  477. You could be setting thr "mode" field incorrectly, probably one of the
  478. "or" methods (srcOr (1) or notSrcOr (5)). For a standard copy, the
  479. transfer method is srcCopy (0).
  480.  
  481. Hope this helps,
  482. Jeremiah
  483.      _______________________________.
  484.     /___  . _____. ___  __  ___  . /
  485.        / / /____/ /__/ / / /__) / /
  486. __    / / _____/   ___/ / ___  / /
  487. \ \__/ / /____/ /\ \   / /__) / /___
  488.  \____/______/ /  \_\ /______/_____/
  489. jerbl@dartmouth.edu
  490.  
  491. "When the world is running down, you make the best of what's still
  492. around."
  493.                          -Sting
  494.  
  495. ---------------------------
  496.  
  497. From: jrk@information-systems.east-anglia.ac.uk (Richard Kennaway)
  498. Subject: Apple Event problem
  499. Date: 12 Jun 92 22:00:25 GMT
  500.  
  501. I recently upgraded an application to use Apple Events.  Just the required
  502. set, i.e. open appl, open doc, print doc, and quit.  I'm not very happy
  503. with the result.
  504.  
  505. It's a text editor.  Suppose I open it by double-clicking on a document it
  506. created, and then search for a string in that document.  So I go, without
  507. a pause, click-click, command-F (to bring up its search dialog), type
  508. string, return.  Previously, this would work.  It would open the doc via
  509. GetAppFiles, then start processing events and find my keystrokes waiting
  510. for it.  With Apple Events, however, I find that WaitNextEvent delivers my
  511. keystrokes before the Apple Event telling it to open a document.  This is
  512. not good - I want to search for the string after the document is open.  I
  513. have to wait until the window appears before I can do anything, and for no
  514. good reason.  (BTW, contrary to the example program and recommendations
  515. way back in IM vol.1, I never call FlushEvents at startup, and for the
  516. same reason.  It imposes an unnecessary wait on the user.  And besides,
  517. dammit, when I type, the machine should listen!)
  518.  
  519. I tried giving AppleEvents priority, by doing a WaitNextEvent(
  520. highLevelMask, ... ) and only if that returned false doing WaitNextEvent(
  521. everyEvent, ... ).  It solved the problem but created worse ones.  I got
  522. various unpleasant weirdness: losing some osEvts, behaving as if
  523. getFrontClicks was on, which it wasn't, etc., 
  524.  
  525. Since it currently has no use for any other Apple Events, I could just set
  526. it back to non-Sys7-aware, but I may want to do more exotic things with
  527. Apple Events in future.
  528.  
  529. Is there a solution?
  530.  
  531. BTW, what is the purpose of the "open application" Apple Event?  Informing
  532. an application that it is open seems remarkably superfluous.  Cogito ergo
  533. sum - if the app is in a position to wonder if it's running, it is.
  534.  
  535. - --
  536. Richard Kennaway     SYS, University of East Anglia, Norwich NR4 7TJ, U.K.
  537. Internet:  jrk@sys.uea.ac.uk               uucp:  ...mcsun!ukc!uea-sys!jrk
  538.  
  539. +++++++++++++++++++++++++++
  540.  
  541. From: jackl@austin.apple.com (Jack Littleton)
  542. Date: Sat, 13 Jun 1992 18:09:17 GMT
  543. Organization: Apple Computer, Inc.
  544.  
  545. In article <9705.9206122200@s4.sys.uea.ac.uk>, jrk@information-systems.east-anglia.ac.uk (Richard Kennaway) writes:
  546. > BTW, what is the purpose of the "open application" Apple Event?  Informing
  547. > an application that it is open seems remarkably superfluous.  Cogito ergo
  548. > sum - if the app is in a position to wonder if it's running, it is.
  549.  
  550. I know this isn't the answer you were looking for (i.e. how to handle events
  551. after immediately opening your document -- sounds tough), but anyway...
  552.  
  553. Only the Finder uses the open application event, and it is indeed sent after
  554. the application has been opened.  What it is supplied for is for
  555. initialization code such as bringing up a empty, untitled window.  It's
  556. simply a signal that your application was opened by the Finder.
  557.  
  558. - --
  559. Jack Littleton
  560. Developer Tools Engineering Group
  561. Apple Computer, Inc.
  562.  
  563.  
  564. +++++++++++++++++++++++++++
  565.  
  566. From: greeny@top.cis.syr.edu (J. S. Greenfield)
  567. Date: 13 Jun 92 21:17:45 GMT
  568. Organization: Syracuse University, CIS Dept.
  569.  
  570. In article <9705.9206122200@s4.sys.uea.ac.uk> jrk@information-systems.east-anglia.ac.uk (Richard Kennaway) writes:
  571. >I recently upgraded an application to use Apple Events.  Just the required
  572. >set, i.e. open appl, open doc, print doc, and quit.  I'm not very happy
  573. >with the result.
  574.  
  575. [...]
  576.  
  577. >I tried giving AppleEvents priority, by doing a WaitNextEvent(
  578. >highLevelMask, ... ) and only if that returned false doing WaitNextEvent(
  579. >everyEvent, ... ).  It solved the problem but created worse ones.  I got
  580. >various unpleasant weirdness: losing some osEvts, behaving as if
  581. >getFrontClicks was on, which it wasn't, etc., 
  582.  
  583. [...]
  584.  
  585. >Is there a solution?
  586. >
  587. >BTW, what is the purpose of the "open application" Apple Event?  Informing
  588. >an application that it is open seems remarkably superfluous.  Cogito ergo
  589. >sum - if the app is in a position to wonder if it's running, it is.
  590.  
  591. I'd say it's there for a very good reason--and it is very much related to
  592. the solution to your problem.  Because of the "open application" event,
  593. you know that no materr *how* your (apple-event aware) application is started,
  594. you will *always* receive an initial apple event after startup (either an
  595. 'oapp', an 'odoc', or a 'pdoc' event).
  596.  
  597. Because of this, you can program your application to await *only* high-level
  598. events *until* the initial apple event arrives.  (You shouldn't stop looking
  599. for apple events just because the first call to WaitNextEvent with the
  600. high-level event mask comes up with a null event.)
  601.  
  602. So set your program to wait for the initial apple event, process it, and then
  603. process any other events that are waiting.  That should make things work the
  604. way you want.
  605.  
  606.  
  607. - -- 
  608. J. S. Greenfield                                         greeny@top.cis.syr.edu
  609. (I like to put 'greeny' here, 
  610. but my d*mn system wants a 
  611. *real* name!)                        "What's the difference between an orange?"
  612.  
  613. +++++++++++++++++++++++++++
  614.  
  615. From: grobbins@Apple.COM (Grobbins)
  616. Date: 14 Jun 92 09:38:57 GMT
  617. Organization: DTS, more or less
  618.  
  619. In article <1992Jun13.171745.18868@newstand.syr.edu> greeny@top.cis.syr.edu writes:
  620. >Because of the "open application" event,
  621. >you know that no materr *how* your (apple-event aware) application is started,
  622. >you will *always* receive an initial apple event after startup (either an
  623. >'oapp', an 'odoc', or a 'pdoc' event).
  624.  
  625. While this is presently true under normal circumstances, application
  626. code should still be written defensively: do not demand an Apple
  627. event after starting up, and do not depend on receiving one of those three.
  628.  
  629. >Because of this, you can program your application to await *only* high-level
  630. >events *until* the initial apple event arrives.  (You shouldn't stop looking
  631. >for apple events just because the first call to WaitNextEvent with the
  632. >high-level event mask comes up with a null event.)
  633. >
  634. >So set your program to wait for the initial apple event, process it, and then
  635. >process any other events that are waiting.  That should make things work the
  636. >way you want.
  637.  
  638. It is not a good idea to mask out everything.  Always handle update
  639. events when they come in, and do remember that OS events are not
  640. queued, so if you are keeping track of being in the foreground or
  641. background by looking at suspend/resume events, then OS events should
  642. never be masked out.
  643.  
  644. There is a way to "prefetch" Apple events via the GetSpecificHighLevelEvent
  645. call, but it's rather ugly and probably best avoided.  See the Event Manager
  646. chapter of Inside Mac VI for documentation on this stuff.
  647.  
  648. Grobbins          grobbins@apple.com
  649.  
  650. Usual disclaimers apply.
  651.  
  652.  
  653. +++++++++++++++++++++++++++
  654.  
  655. From: jpugh@apple.com (Jon Pugh)
  656. Date: 15 Jun 92 05:44:59 GMT
  657. Organization: Apple Computer, Inc.
  658.  
  659. In article <1992Jun13.180917.12101@pcnntp.apple.com>, jackl@austin.apple.com (Jack Littleton) writes:
  660. > In article <9705.9206122200@s4.sys.uea.ac.uk>, jrk@information-systems.east-anglia.ac.uk (Richard Kennaway) writes:
  661. > > BTW, what is the purpose of the "open application" Apple Event?  Informing
  662. > > an application that it is open seems remarkably superfluous.  Cogito ergo
  663. > > sum - if the app is in a position to wonder if it's running, it is.
  664. > I know this isn't the answer you were looking for (i.e. how to handle events
  665. > after immediately opening your document -- sounds tough), but anyway...
  666. > Only the Finder uses the open application event, and it is indeed sent after
  667. > the application has been opened.  What it is supplied for is for
  668. > initialization code such as bringing up a empty, untitled window.  It's
  669. > simply a signal that your application was opened by the Finder.
  670.  
  671. I would like to add that if you launch and don't get an Open Application
  672. event, you should just go straight to your event loop without any fuss.
  673. This may be done to get you to launch in the background, like a daemon for
  674. example. This way you won't bother the user of the machine, who won't be
  675. looking for you, since you would've gotten an oapp, odoc or pdoc if he was
  676. looking at your program.
  677.  
  678. Once again, no oapp, no new doc. Just go to the main event loop after 
  679. initializing everything. You should be ready to do a new doc or whatever.
  680.  
  681. Jon Pugh
  682. kAERegistrar
  683.  
  684. +++++++++++++++++++++++++++
  685.  
  686. From: brady@cs.tcd.ie (Brady Michael)
  687. Organization: Trinity College, Dublin (Computer Science)
  688. Date: Mon, 15 Jun 1992 09:43:25 GMT
  689.  
  690. In article <68674@apple.Apple.COM> grobbins@Apple.COM (Grobbins) writes:
  691. >
  692. >While this is presently true under normal circumstances, application
  693. >code should still be written defensively: do not demand an Apple
  694. >event after starting up, and do not depend on receiving one of those three.
  695.  
  696. I'm looking for a little clarification on this:
  697. The way I have set up my application - Open Prolog - is this: after it starts up
  698. it looks for a pending high-level event, of type OAPP, ODOC or PDOC. If
  699. none of these are present, somewhere in the event queue, then the
  700. application presumes that it has been started in a non-HLE environment
  701. and goes on to getAppFiles, etc.
  702. Are you saying this is inadvisable?
  703.  
  704. Mike
  705. - -- 
  706. Michael Brady                         brady@cs.tcd.ie
  707. Department of Computer Science
  708. University of Dublin, Trinity College Dublin, Ireland
  709.  
  710.  
  711. +++++++++++++++++++++++++++
  712.  
  713. From: sstorkel@waimea.oracle.com (Scott Storkel)
  714. Organization: Oracle Corporation, Belmont, CA
  715. Date: Mon, 15 Jun 1992 18:12:47 GMT
  716.  
  717.  
  718. In article <1992Jun15.094325.6324@cs.tcd.ie> brady@cs.tcd.ie (Brady Michael) writes:
  719.  
  720. >I'm looking for a little clarification on this:
  721. >The way I have set up my application - Open Prolog - is this: after it starts up
  722. >it looks for a pending high-level event, of type OAPP, ODOC or PDOC. If
  723. >none of these are present, somewhere in the event queue, then the
  724. >application presumes that it has been started in a non-HLE environment
  725. >and goes on to getAppFiles, etc.
  726. >Are you saying this is inadvisable?
  727.  
  728. Okay, here's what I'd do. I think this is correct, but somebody from Apple
  729. can point me down the right path if I've strayed...
  730.  
  731. 1. Initialize everything. This includes all of the Toolbox managers as well
  732.    as application initialization code.
  733.  
  734. 2. Call Gestalt and see if the Apple Event Manager is present. If yes, goto 4.
  735.  
  736. 3. AE Manager isn't available, so open/print files using CountAppFiles(),
  737.    GetAppFiles(), etc. Create an "untitled" document if you would normally
  738.    do so in response to an oapp Apple Event.
  739.  
  740. 4. Enter your main event loop! Be sure to handle the oapp, odoc, and pdoc
  741.    Apple Events. If you get odoc or pdoc events, open or print the
  742.    corresponding files. If you get an oapp event, open an "untitled" document
  743.    or perform any other user visible actions that should happen when your
  744.    program is launched.
  745.  
  746. It's important to note that #4 should be your real, live, handle-everything
  747. main event-loop. Any questions?
  748.  
  749.  
  750.                                 -- Scott
  751.  
  752.  
  753. ==============================================================================
  754. Code Warrior                    500 Oracle Parkway
  755. Advanced Products Division            Box 659405
  756. Oracle Corporation                Redwood Shores, CA. 94065
  757. 415-506-2493                    FAX: 415-506-7216
  758. ==============================================================================
  759. - --
  760.  
  761. ==============================================================================
  762. Code Warrior                    500 Oracle Parkway
  763. Advanced Products Division            Box 659405
  764. Oracle Corporation                Redwood Shores, CA. 94065
  765. 415-506-2493                    FAX: 415-506-7216
  766. ==============================================================================
  767.  
  768. +++++++++++++++++++++++++++
  769.  
  770. From: baugh@voyager.east.isx.com (Earl Baugh)
  771. Date: 16 Jun 92 20:34:38 GMT
  772. Organization: ISX Corporation, East Coast Office
  773.  
  774. In article <1992Jun13.180917.12101@pcnntp.apple.com> jackl@austin.apple.com (Jack Littleton) writes:
  775. >In article <9705.9206122200@s4.sys.uea.ac.uk>, jrk@information-systems.east-anglia.ac.uk (Richard Kennaway) writes:
  776. >> BTW, what is the purpose of the "open application" Apple Event?  Informing
  777. >> an application that it is open seems remarkably superfluous.  Cogito ergo
  778. >> sum - if the app is in a position to wonder if it's running, it is.
  779. >
  780. >Only the Finder uses the open application event, and it is indeed sent after
  781. >the application has been opened.  
  782.  
  783.     Sorry to say, that's not the only way an application gets an Open
  784. Application Event.  Any application that uses LaunchApplication to launch
  785. your application can cause it to get an Open Application event.   (We
  786. won't discuss how badly the LaunchApplication call is documented.....)
  787. BTW, your application can get just about any event from the Launching program,
  788. open document comes to mind...
  789.  
  790. 'later
  791.  
  792. - -- 
  793.     Earl D. Baugh Jr.
  794.     ISX Corporation 
  795.     Internet : baugh@voyager.east.isx.com
  796.  
  797. +++++++++++++++++++++++++++
  798.  
  799. From: jpugh@apple.com (Jon Pugh)
  800. Date: 26 Jun 92 04:35:46 GMT
  801. Organization: Apple Computer, Inc.
  802.  
  803. In article <1992Jun15.094325.6324@cs.tcd.ie>, brady@cs.tcd.ie (Brady Michael) writes:
  804. > The way I have set up my application - Open Prolog - is this: after it starts up
  805. > it looks for a pending high-level event, of type OAPP, ODOC or PDOC. If
  806. > none of these are present, somewhere in the event queue, then the
  807. > application presumes that it has been started in a non-HLE environment
  808. > and goes on to getAppFiles, etc.
  809. > Are you saying this is inadvisable?
  810.  
  811. Yes, this is inadvisable.
  812.  
  813. Call Gestalt and see if the AE manager is available.  If you have the SIZE
  814. resource's highLevelEventAware bit then you will get an AE and you can just
  815. relax, initialize and idle, dealing with whatever you get or don't get when
  816. you do or don't get it, as you should.
  817.  
  818. If the AEM is not available, check the appFiles.
  819.  
  820. Jon
  821. kAERegistrar
  822.  
  823.  
  824. ---------------------------
  825.  
  826. From: jstevens@crick.ssctr.bcm.tmc.edu (Jason Philip Stevens)
  827. Subject: Getting the text from a TERec
  828. Date: 15 Jun 1992 17:46:56 GMT
  829. Organization: Baylor College of Medicine, Houston, Tx
  830.  
  831.  
  832. I'm trying to extract the text from a TERec into a standard C-style
  833. char* .  Suppose I have a TERec**, TEHandle.
  834.  
  835. Accoring to IM-1, p377, the hText member is a "handle to the text to
  836. be edited."  if I try *(*TEHandle)->hText, I get garbage.  If I try to
  837. use the TEGetText routine, I get a CharsHandle returned (a handle to a
  838. packed array of chars).  If I dereference that, I also get garbage.
  839. How do I actually get my hands on a char*?
  840.  
  841. BTW, I've tried using PtoCstr, on the assumption that the resultant string
  842. would be in Pascal format, and while it compiles, in use it generates a 
  843. bus error...
  844.  
  845. Thanks for any help...
  846.  
  847. - -jps
  848. - -- 
  849. Jason Stevens            Internet:  jstevens@bcm.tmc.edu
  850. Network User Services        Voice:  (713) 798-7370
  851. Baylor College of Medicine    Opinions expressed are mine alone.
  852.  
  853.  
  854. +++++++++++++++++++++++++++
  855.  
  856. From: zobkiw@world.std.com (Joe Zobkiw)
  857. Organization: The World Public Access UNIX, Brookline, MA
  858. Date: Tue, 16 Jun 1992 01:03:28 GMT
  859.  
  860. In article <12523@gazette.bcm.tmc.edu> jstevens@crick.ssctr.bcm.tmc.edu (Jason Philip Stevens) writes:
  861. >
  862. >I'm trying to extract the text from a TERec into a standard C-style
  863. >char* .  Suppose I have a TERec**, TEHandle.
  864. >
  865.  
  866. Well, first of all, if your TERec contains more than 255 characters of text
  867. you may bomb when you try to cast it as a Str255. However, if you want to do
  868. this you can use something like:
  869.  
  870. void TE2Str(TEHandle te, Str255 str)
  871. {
  872.     GetIText((te)->hText, str);
  873. }
  874.  
  875. void Str2TE(Str255 str, TEHandle te)
  876. {
  877.     TESetText((Ptr)&str[1], (long)str[0], te);
  878. }
  879.  
  880. This might also help you with your other problem, finding the text. 
  881. Remember, hText is a _Handle_ to the text in question. Two dereferences
  882. of a Handle get you to it's data.
  883.  
  884.  
  885. - -- 
  886. - -- joe zobkiw                      Internet: zobkiw@world.std.com
  887. - --                                      AOL: AFL Zobkiw  
  888. - -- mac.synthesis.MIDI.THINK C.OOP
  889. - -- asm.comm.networks.cool tunes...
  890.  
  891. +++++++++++++++++++++++++++
  892.  
  893. From: lari@bach.cs.unc.edu (Humayun Lari)
  894. Date: 16 Jun 92 18:12:33 GMT
  895. Organization: University of North Carolina, Chapel Hill
  896.  
  897. In article <Bpwyxu.1n6@world.std.com> zobkiw@world.std.com (Joe Zobkiw) writes:
  898. >In article <12523@gazette.bcm.tmc.edu> jstevens@crick.ssctr.bcm.tmc.edu (Jason Philip Stevens) writes:
  899. >>
  900. >>I'm trying to extract the text from a TERec into a standard C-style
  901. >>char* .  Suppose I have a TERec**, TEHandle.
  902. >>
  903. >
  904. >Well, first of all, if your TERec contains more than 255 characters of text
  905. >you may bomb when you try to cast it as a Str255. However, if you want to do
  906. >this you can use something like:
  907. >
  908. >void TE2Str(TEHandle te, Str255 str)
  909. >{
  910. >    GetIText((te)->hText, str);
  911. >}
  912.  
  913. Um, isn't GetIText only for dialogs? Perhaps this might be a bit better:
  914.  
  915. OSErr TE2CStr(TEHandle te, char *str)
  916. {
  917.     short  textLength;
  918.  
  919.     textLength = (**te).teLength;
  920.     str = (char *)NewPtr(textLength + 1);
  921.     if (MemError() != noErr)
  922.         return MemError();
  923.  
  924.     BlockMove( (Ptr)(*TEGetText(te)), (Ptr)str, textLength);
  925.     str[textLength] = '\0';
  926.  
  927.     return noErr;
  928. }
  929.  
  930. Since you're using C, this should work OK no matter how much text the TERec
  931. contains (up to the 32K limit). Anyone see a silly mistake? (My C's kind of
  932. rusty.)
  933.  
  934. >
  935. >void Str2TE(Str255 str, TEHandle te)
  936. >{
  937. >    TESetText((Ptr)&str[1], (long)str[0], te);
  938. >}
  939.  
  940. void CStr2TE(char *str, TEHandle te)
  941. {
  942.     TESetText((Ptr)str, strlen(str), te);
  943. }
  944.  
  945. >
  946. >This might also help you with your other problem, finding the text. 
  947. >Remember, hText is a _Handle_ to the text in question. Two dereferences
  948. >of a Handle get you to it's data.
  949.  
  950. After years and years, I still forget... :-)
  951.  
  952.  
  953. Humayun Lari
  954. (lari@cs.unc.edu)
  955.  
  956. +++++++++++++++++++++++++++
  957.  
  958. From: ewylie@ocf.berkeley.edu (Elizabeth Wylie)
  959. Date: 17 Jun 92 04:26:05 GMT
  960. Organization: U.C. Berkeley Open Computing Facility
  961.  
  962. > >void TE2Str(TEHandle te, Str255 str) >{ > GetIText((te)->hText,
  963. > str); >} 
  964. > Um, isn't GetIText only for dialogs? Perhaps this might be a bit
  965. > better:
  966.  
  967. I noticed the GetIText call as well, but thought about it and had to smile.
  968.  
  969. ":-)"
  970.  
  971. When you perform a GetDItem on an edit text in a dialog, you get a handle to
  972. the text of the item.  GetIText just copies at most 255 bytes of this handle
  973. into a pascal string.  So long as it is passed a handle to text, you're OK.
  974.  
  975. vrey nice.
  976. - -Elizabeth
  977.  
  978. +++++++++++++++++++++++++++
  979.  
  980. From: zobkiw@world.std.com (Joe Zobkiw)
  981. Date: 17 Jun 92 10:46:38 GMT
  982. Organization: The World Public Access UNIX, Brookline, MA
  983.  
  984. The GetIText 'trick' came from THINK Reference. I will not take credit
  985. for it. I just found it to be an easy to understand way of doing things :)
  986.  
  987.  
  988. - -- 
  989. - -- joe zobkiw                      Internet: zobkiw@world.std.com
  990. - --                                      AOL: AFL Zobkiw  
  991. - -- mac.synthesis.MIDI.THINK C.OOP
  992. - -- asm.comm.networks.cool tunes...
  993.  
  994. +++++++++++++++++++++++++++
  995.  
  996. Date: 24 Jun 92 19:33:49 GMT
  997. From: jopa@tkk.tele.fi (Jorma Paananen)
  998.  
  999. lari@bach.cs.unc.edu (Humayun Lari) writes:
  1000. > void CStr2TE(char *str, TEHandle te)
  1001. > {
  1002. >     TESetText((Ptr)str, strlen(str), te);
  1003. > }
  1004.  
  1005. >From IM I-383:
  1006.   "TESetText doesn't dispose of any text currently in the edit record"
  1007.  
  1008. What is the correct way to free old text ?
  1009.  
  1010. Jorma
  1011. jopa@tkk.tele.fi
  1012.  
  1013. +++++++++++++++++++++++++++
  1014.  
  1015. From: lari@bach.cs.unc.edu (Humayun Lari)
  1016. Date: 25 Jun 92 20:52:29 GMT
  1017. Organization: University of North Carolina, Chapel Hill
  1018.  
  1019. In article <jopa.709414429@tkk.tele.fi> jopa@tkk.tele.fi (Jorma Paananen) writes:
  1020. >lari@bach.cs.unc.edu (Humayun Lari) writes:
  1021. >> void CStr2TE(char *str, TEHandle te)
  1022. >> {
  1023. >>     TESetText((Ptr)str, strlen(str), te);
  1024. >> }
  1025. >
  1026. >From IM I-383:
  1027. >  "TESetText doesn't dispose of any text currently in the edit record"
  1028. >
  1029. >What is the correct way to free old text ?
  1030.  
  1031.  
  1032. Well, I *did* have a feeling that it couldn't be that simple :-).
  1033. Maybe this will work: (Anyone see more amazingly silly mistakes?)
  1034.  
  1035. void CStr2TE(char *str, TEHandle te)
  1036. {
  1037.      TESetSelect(0, 32767, te);   /* IM I-385 */
  1038.      TEDelete(te);                /* IM I-387 */
  1039.      TESetText((Ptr)str, strlen(str), te);
  1040. }
  1041.  
  1042. Note that the edit record should be inactive, or else the selection will be
  1043. highlighted. If the string is long, you might prefer to use TEGetText to access
  1044. the text handle directly, so you can check for memory errors when resizing the
  1045. handle to fit.
  1046.  
  1047. Humayun Lari
  1048. (lari@cs.unc.edu)
  1049. ObSig: "Technology changes rapidly; people and meaning do not." -- Kevin Bjorke
  1050.  
  1051. ---------------------------
  1052.  
  1053. End of C.S.M.P. Digest
  1054. **********************
  1055.